package com.icee.myth.manager.pipelineFactory;

import com.icee.myth.common.encoder.Type4BytesLengthFieldProtobufEncoder;
import com.icee.myth.manager.channelHandler.DeamonToManagerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

/**
 *
 * @author liuxianke
 */
public class DeamonToManagerPipelineInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 2, 2, 0, 0));
        ch.pipeline().addLast("customEncoder", new Type4BytesLengthFieldProtobufEncoder());

        ch.pipeline().addLast("handler", new DeamonToManagerHandler());
    }
}
